package com.hzqy.persistence.dao.statistics;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.hzqy.persistence.dao.core.PersistenceDao;
import com.hzqy.web.vo.PmsUserVo;
import com.hzqy.web.vo.StatDataSilentUserVo;

@Repository
public class SilentUserDao extends PersistenceDao<PmsUserVo, Integer>{
	protected final Logger LOG = LoggerFactory.getLogger(SilentUserDao.class);

	public int selectSilentUserCount(StatDataSilentUserVo statDataSilentUserVo) {
		return getSqlSession().selectOne(this.getNamespace()+"selectSilentUserCount", statDataSilentUserVo);
	}
	
	public List<StatDataSilentUserVo> selectSilentUserList(Map<String,Object> map){
		return getSqlSession().selectList(this.getNamespace() + "selectSilentUserList", map);
	}
	
	public List<StatDataSilentUserVo> selectSilentUserExcelList(Map<String,Object> map){
		return getSqlSession().selectList(this.getNamespace() + "selectSilentUserExcelList", map);
	}

	public int insertUserList(List<StatDataSilentUserVo> insertUserList) {
		int successCount = 0;
		int size = 10000;
		int index = 0;
		int length = insertUserList.size();
		LOG.debug("沉默用户列表导入，一共需要入库 " + length + "条记录, 每次最多入库" + size + "条记录。");
		Map<String, Object> map = new HashMap<String, Object>();
		while(length > index * size ) {
			int from = index * size;
			int to = (index * size + size) > length ? length : (index * size + size);
			LOG.debug("开始入库 " + from + " ~ " + to);
			List<StatDataSilentUserVo> list = insertUserList.subList(from, to);
			map.put("list", list);
			int count = getSqlSession().insert(this.getNamespace() + "insertUserList", map);
			successCount += count;
			index ++;
		}
		return successCount;
	}
	
}
